package pl.com.qapps.datastore.objectify;

import java.io.IOException;
import java.util.Arrays;

import pl.com.qapps.datastore.BytesHelper;
import pl.com.qapps.datastore.Datastore;
import pl.com.qapps.datastore.GaeHelper;
import pl.com.qapps.datastore.berkeley.BerkeleyDatastore;
import pl.com.qapps.datastore.objectify.test.Person;
import pl.com.qapps.datastore.objectify.test.Personn;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.Entity;
import com.googlecode.objectify.Objectify;

public class Test {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		GaeHelper.registerEnvironment();
		
		Datastore ds = BerkeleyDatastore.newLocal("./datastore");
		Datastore remote = BerkeleyDatastore.newRemote("qapps.com.pl:/", 80);
		
		OfyService.init(ds);

		OfyService.register(Person.class);
		OfyService.register(Personn.class);

		Objectify ofy = OfyService.begin();

		Personn p = new Personn();
		p.id = 2L;
		p.name = "Kuba";
		p.email = "jakub.dykowski@gmail.com";

		long start = System.currentTimeMillis();
//		ofy.put(p);
		long stop = System.currentTimeMillis();
		System.out.println("put duration: " + (stop - start) + " milisecs");

		// start = System.currentTimeMillis();
		// ofy.put(p);
		// stop = System.currentTimeMillis();
		// System.out.println("put duration: " + (stop - start) + " milisecs");
		//
		// start = System.currentTimeMillis();
		// ofy.put(p);
		// stop = System.currentTimeMillis();
		// System.out.println("put duration: " + (stop - start) + " milisecs");
		//
		// start = System.currentTimeMillis();
		// for (int i = 0; i < 1; i++) {
		// ofy.put(new Person());
		// }
		// stop = System.currentTimeMillis();
		// System.out.println("put duration: " + (stop - start) + " milisecs");

		System.out.println(Arrays.toString(BytesHelper.serialize("Personn")));
		System.out.println(Arrays.toString(BytesHelper.serialize(2L)));
		
		 start = System.currentTimeMillis();
		 Personn fetched = ofy.get(Personn.class, 2L);
		 stop = System.currentTimeMillis();
		 System.out.println(fetched);
		 System.out.println("get duration: " + (stop - start) + " milisecs");
		
		// System.out.println(ofy.query().count());
		// System.out.println(ofy.query(Person.class).filter("name >=", "kub")
		// .filter("name <=", "luba").filter("age !=", 18).filter("age !=", 10)
		// .filter("email", "jakistam@costam").list());
		
//		System.out.println(ofy.query(Person.class).list());
		
		ds.close();
	}
}
